package arithmetic.socket.netty.protbuff;

import com.google.protobuf.InvalidProtocolBufferException;

import arithmetic.socket.netty.protbuff.MyDataInfo.Person;


/**
 * protoc --java_out=src/main/java src/main/java/arithmetic/socket/netty/protBuff/TestPerson.proto
 * @author jiangfeng
 * Created on 2020-03-09
 */
public class TestProtoBuf {
    public static void main(String[] args) throws InvalidProtocolBufferException {
        Person wqe = Person.newBuilder().setAddress("wqew我").setAge(2).setName("234").build();
        System.out.println(wqe.toString());
        byte[] bytes = wqe.toByteArray();

        Person person = Person.parseFrom(bytes);

        System.out.println(person);
        System.out.println(person.toString());
        System.out.println(person.getAddress());
    }

    // netty 解码器handler:

    // pipeline.addLast(new ProtobufVarint32FrameDecoder());
    // pipeline.addLast(new ProtobufDecoder(MyDataInfo.Person.getDefaultInstance()));
    // pipeline.addLast(new ProtobufVarint32LengthFieldPrepender());
    // pipeline.addLast(new ProtobufEncoder());
}
